import React from 'react';
import {
	observer,
	inject
} from 'mobx-react';
import {
	AlertPage,
	Loading,
} from '../../public/learn';
import Top from './Top';
import '../../style/report.less';

@inject('commonStore')
@inject('hrmOriginalPunchRecord')
@observer
export default class OriginalPunchRecord extends React.Component {
	constructor(props) {
		super(props);
	}

	componentWillMount() {
		const {
			pageConfig
		} = this.props.hrmOriginalPunchRecord;

		const params = {
			...pageConfig,
			customizedStore: this.props.hrmOriginalPunchRecord,
		};

		['resetStorePropertys', 'setPageConfig', 'getPermissionInfo'].map((f, i) => {
			this.props.commonStore[f](i === 1 && params);
		});

	}

	componentWillReceiveProps(nextProps) {
		if (this.props.location.key !== nextProps.location.key) {
			this.props.commonStore.refreshPage();
		}
	}

	render() {
		const {
			commonStore,
		} = this.props, {
			pageAccessPermission
		} = commonStore, {
			hasRight,
			loading
		} = pageAccessPermission;

		if (!hasRight) {
			return loading ? <Loading ecId={`${this && this.props && this.props.ecId || ''}_Loading@sjfg0a`} size='lg'/> : <AlertPage ecId={`${this && this.props && this.props.ecId || ''}_AlertPage@0kglmn`} />
		} else {
			return (
				<Top ecId={`${this && this.props && this.props.ecId || ''}_Top@m1537z`} />
			)
		}
	}
}